/**
 * 生成路由
 *  @param {Array} routerlist 格式化路由
 *  @returns
 */
export function addRouter(routerlist) {
    // console.log('routerlist', routerlist)
    const router = []
    routerlist.forEach(e => {
        //先排除按钮类型
        // console.log("递归--------------e",e);
        let e_new = {
            // component: () => import(`@/views/${e.component}`)
            // component: () => require(`@/views/${e.component}`),
            // name: e.menuName,
            component: resolve => require([`@/views/${e.component}`], resolve),
            hidden: e.visible === '1' ? true : false,
            meta: e.meta,
            path: e.path,

        }
        // console.log('e_new', e_new)
        // 继续循环遍历
        if (e.children) {
            e_new = Object.assign({}, e_new, { children: addRouter(e.children) })
        }
        if (e.redirect) {
            e_new = Object.assign({}, e_new, { redirect: e.redirect })
        }
        if (e.icon !== '' && e.menuName !== '') {
            e_new = Object.assign({}, e_new, {
                meta: { title: e.menuName, icon: e.icon, select: e.icon, iconActive: `${e.icon}_active` }
                // meta: { title: e.menuName, icon: e.icon ,icon_active: "menu_active"}
            })
        } else if (e.menuName !== '' && e.icon === '') {
            e_new = Object.assign({}, e_new, { meta: { title: e.menuName } })
        }

        router.push(e_new)
    })
    // console.log('router1', router)
    return router
}